Developer --> Technical Publications
PATHJava Developer Documentation > Mac OS Runtime for Java > MRJToolkit > Programming With MRJToolkit


Finding an Application With a Given Creator

If you want to find an application with a given creator, you can call the findApplication method. For example, if you have an HTML file with a given browser's creator, you can search for the browser and then open the file with it. The code fragment in Listing 1-3 searches for the SimpleText application and then launches it by passing the file to Runtime.runtime.exec . (In a similar manner, you could search for a browser and have it open a local HTML file.)

Listing 1-3 Finding the path to an application

try {
        File cw = MRJFileUtils.findApplication(new MRJOSType("ttxt"));

        // launch SimpleText with our new text file
        String params[] = { cw.toString(), f.toString() };

        // parameters to runtime exec:
        // { AppToRun, FileToOpen, ... }
        Runtime.getRuntime().exec(params);

    } catch (Exception e) {
        fail("Can't find SimpleText", e);
        return;
        }

The findApplication method searches the Mac OS desktop database looking for an application with the correct creator. If more than one copy of the application exists, findApplication may find a copy different from the one you expect, depending on the state of the desktop database.


© 1998 Apple Computer, Inc. — (Last Updated 10 Dec 98)

Previous | Back Up One Level | Next |